class NGram
  def to_a
    return @arr
  end

  def initialize n
    @arn = n
    @arr = []
  end

  def << word
    @arr.push word
    @arr.shift if @arr.size > @arn
  end

  def ready?
    @arr.size == @arn
  end

  def self.test
    n1 = NGram.new 1
    raise "empty n_gram size 1 ready? fails" if n1.ready?
    n1 << "dima"
    raise "n_gram size 1 ready? fails" unless n1.ready?
    raise "n_gram size 1 to_a fail" unless n1.to_a == %w[dima]
    n1 << "world"
    raise "n_gram size 1 ready? fails" unless n1.ready?
    raise "n_gram size 1 to_a fail" unless n1.to_a == %w[world]
    n3 = NGram.new 3
    raise "empty n_gram size 3 ready? fails" if n3.ready?
    n3 << "dima"
    n3 << "love"
    raise "empty n_gram size 3 ready? fails" if n3.ready?
    n3 << "alina"
    raise "n_gram size 3 ready? fails" unless n3.ready?
    raise "n_gram size 3 to_a fail" unless n3.to_a == %w[dima love alina]
    n3 << "darling"
    raise "n_gram size 3 ready? fails" unless n3.ready?
    raise "n_gram size 3 to_a fail" unless n3.to_a == %w[love alina darling]
  end
end
